﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ObjectBakery.Interfaces;

namespace ObjectBakery
{
    public class ScriptInvoker
    {
        public T Execute<T>(string strSource, string strType, string strMethod)
        {
            // Create an instance of MarshalbyRefType in the second AppDomain.  A proxy to the object is returned.

            var proxy = new ObjectBakery.ScriptProxy(strType, strSource, Language.CSharp);
            var type = proxy.ProxiedObject.GetType();

            AppDomain sandbox = AppDomain.CreateDomain("sandbox");
            IScriptObject script = (IScriptObject)sandbox.CreateInstanceAndUnwrap(type.Assembly.FullName, type.FullName);

            return (T)script.Execute();


            //// Call a method on the object via the proxy, passing the 
            //// default AppDomain's friendly name in as a parameter.
            //object res = proxy.InvokeMethod(strSource, strMethod);

            //return res;
        }
    }



}
